/**
 * 工具类
 */
import CryptoJS from 'crypto-js'
/**
 * 
 * @param {*待加密的字符串} str 
 * @param {*相当于是密钥} strKey 
 * @param {*相当于是双层密钥的意思} strIv
 *  strKey strIv长度需要和后面商量
 */
export let encrypt = function (str, strKey, strIv) { //加密
    let key = CryptoJS.enc.Utf8.parse(strKey);
    let iv = CryptoJS.enc.Utf8.parse(strIv);
    let encrypted = '';

    let srcs = CryptoJS.enc.Utf8.parse(str);
    encrypted = CryptoJS.AES.encrypt(srcs, key, {
        iv: iv,
        mode: CryptoJS.mode.CBC,
        padding: CryptoJS.pad.Pkcs7
    });
	// console.log("DDD"+str);
	// console.log("DDD"+strKey);
	// console.log("DDD"+strIv);
    return encrypted.ciphertext.toString();
};
export let decrypt = function (str, strKey, strIv) { //解密
    let key = CryptoJS.enc.Utf8.parse(strKey);
    let iv = CryptoJS.enc.Utf8.parse(strIv);
    let encryptedHexStr = CryptoJS.enc.Hex.parse(str);
    let srcs = CryptoJS.enc.Base64.stringify(encryptedHexStr);
    let decrypt = CryptoJS.AES.decrypt(srcs, key, {
        iv: iv,
        mode: CryptoJS.mode.CBC,
        padding: CryptoJS.pad.Pkcs7
    });
    let decryptedStr = decrypt.toString(CryptoJS.enc.Utf8);
    return decryptedStr.toString();
};
export function getTimes() {
    return new Date().getTime()
};